package com.dengc.service.impl;

import com.dengc.mapper.GoodsStorageRecordMapper;
import com.dengc.pojo.GoodsStorageRecord;
import com.dengc.pojo.GoodsSupplier;
import com.dengc.service.GoodsStorageRecordService;
import com.dengc.utils.Contants;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("GoodsStorageRecordService")
public class GoodsStorageRecordServiceImpl implements GoodsStorageRecordService {

    @Autowired
    GoodsStorageRecordMapper goodsStorageRecordMapper;

    //分页功能实现
    @Override
    public PageInfo<GoodsStorageRecord> getGoodsStorageRecordByPage(GoodsStorageRecord goodsStorageRecord, int pageNum) {
        //开启分页
        PageHelper.startPage(pageNum, Contants.PAGESIZE);
        //分页好的数据保存起来
        List<GoodsStorageRecord> list = goodsStorageRecordMapper.getGoodsStorageRecordByCondition(goodsStorageRecord);
        return new PageInfo<>(list);
    }

    //添加功能实现
    @Override
    public int addGoodsStorageRecord(GoodsStorageRecord goodsStorageRecord) {
        return goodsStorageRecordMapper.addGoodsStorageRecord(goodsStorageRecord);
    }

    //根据id查询商品入库信息
    @Override
    public GoodsStorageRecord getAllRecordById(Integer id) {
        GoodsStorageRecord goodsStorageRecord = new GoodsStorageRecord();
        goodsStorageRecord.setId(id);
        List<GoodsStorageRecord> list = goodsStorageRecordMapper.getGoodsStorageRecordByCondition(goodsStorageRecord);
        return list.get(0);
    }

    //修改功能实现
    @Override
    public int updateGoodsStorageRecord(GoodsStorageRecord goodsStorageRecord) {
        return goodsStorageRecordMapper.updateGoodsStorageRecord(goodsStorageRecord);
    }

    //删除功能实现
    @Override
    public int deletGoodsStorageRecord(Integer id) {
        return goodsStorageRecordMapper.deletGoodsStorageRecord(id);
    }


}
